#pragma once

#include "InformationFlow.h"

#include "ActivityEdge.h"
#include "Classifier.h"
#include "Connector.h"
#include "Message.h"
#include "NamedElement.h"
#include "Relationship.h"

namespace uml {

InformationFlow::InformationFlow(const QString& umlType)
    : PackageableElement(umlType) {}

void InformationFlow::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    DirectedRelationship::fromJson(json, errorList);
    PackageableElement::fromJson(json, errorList);
    JsonSerializable::fromJsonArray(conveyeds_, "conveyeds", json, errorList);
    JsonSerializable::fromJsonArray(informationSources_, "informationSources", json, errorList);
    JsonSerializable::fromJsonArray(informationTargets_, "informationTargets", json, errorList);
    JsonSerializable::fromJsonArray(realizations_, "realizations", json, errorList);
    JsonSerializable::fromJsonArray(realizingActivityEdges_, "realizingActivityEdges", json, errorList);
    JsonSerializable::fromJsonArray(realizingConnectors_, "realizingConnectors", json, errorList);
    JsonSerializable::fromJsonArray(realizingMessages_, "realizingMessages", json, errorList);
}

void InformationFlow::toJson(QJsonObject& json) {
    DirectedRelationship::toJson(json);
    PackageableElement::toJson(json);
    JsonSerializable::toJsonArray(conveyeds_, "conveyeds", json);
    JsonSerializable::toJsonArray(informationSources_, "informationSources", json);
    JsonSerializable::toJsonArray(informationTargets_, "informationTargets", json);
    JsonSerializable::toJsonArray(realizations_, "realizations", json);
    JsonSerializable::toJsonArray(realizingActivityEdges_, "realizingActivityEdges", json);
    JsonSerializable::toJsonArray(realizingConnectors_, "realizingConnectors", json);
    JsonSerializable::toJsonArray(realizingMessages_, "realizingMessages", json);
}

/// <summary>
/// conveyeds getter
/// Specifies the information items that may circulate on this information flow.
/// </summary>
vector<shared_ptr<Classifier>>& InformationFlow::conveyeds() {
    return conveyeds_;
}

/// <summary>
/// informationSources getter
/// Defines from which source the conveyed InformationItems are initiated.
/// </summary>
vector<shared_ptr<NamedElement>>& InformationFlow::informationSources() {
    return informationSources_;
}

/// <summary>
/// informationTargets getter
/// Defines to which target the conveyed InformationItems are directed.
/// </summary>
vector<shared_ptr<NamedElement>>& InformationFlow::informationTargets() {
    return informationTargets_;
}

/// <summary>
/// realizations getter
/// Determines which Relationship will realize the specified flow.
/// </summary>
vector<shared_ptr<Relationship>>& InformationFlow::realizations() {
    return realizations_;
}

/// <summary>
/// realizingActivityEdges getter
/// Determines which ActivityEdges will realize the specified flow.
/// </summary>
vector<shared_ptr<ActivityEdge>>& InformationFlow::realizingActivityEdges() {
    return realizingActivityEdges_;
}

/// <summary>
/// realizingConnectors getter
/// Determines which Connectors will realize the specified flow.
/// </summary>
vector<shared_ptr<Connector>>& InformationFlow::realizingConnectors() {
    return realizingConnectors_;
}

/// <summary>
/// realizingMessages getter
/// Determines which Messages will realize the specified flow.
/// </summary>
vector<shared_ptr<Message>>& InformationFlow::realizingMessages() {
    return realizingMessages_;
}

} // namespace uml
